
docker pull timescale/timescaledb:2.6.0-pg14
# 当前目录
CURRENT_DIR=$(
  cd $(dirname $0)
  pwd
)
echo $CURRENT_DIR
DATA_DIR=${CURRENT_DIR}/data/
echo $DATA_DIR
echo "新建一个存储timescaladb数据的目录"
if [ ! -e $DATA_DIR ]; then
  mkdir -p $DATA_DIR
  echo $DATA_DIR + "新建OK"
fi
export_container_name='timescaledb'
export_pg_password='qiuwen123456'

init_main() {
  run_shell=$(
    docker run \
    --name ${export_container_name} \
    -e POSTGRES_PASSWORD=${export_pg_password} \
    -p 5433:5432 \
    -v $DATA_DIR:/var/lib/postgresql/data \
    -d \
    timescale/timescaledb:2.6.0-pg14
  )
  echo "run_shell 执行结果"
  echo "$run_shell"
}

start_main() {
  echo "start_main"
  temp_shell=$(docker start ${export_container_name})
  echo "start_main 执行结果"
  echo "$temp_shell"
}

stop_main() {
  echo "stop_main"
  stop_shell=$(docker stop ${export_container_name})
  echo "stop_main 执行结果"
  echo "$stop_shell"
}

restart_main() {
  stop_main
  start_main
}

remove_main() {
  stop_shell=$(docker stop ${export_container_name})
  echo "stop_shell 执行结果"
  echo "$stop_shell"
  remove_shell=$(docker rm ${export_container_name})
  echo "remove_shell 执行结果"
  echo "$remove_shell"
}
# 主函数
main() {
  echo "请输入你要进行的操作;init;start;stop;restart;remove"
  read input_action
  echo "$input_action"
  if test $input_action = "init"; then
    init_main
  elif test $input_action = "start"; then
    start_main
  elif test $input_action = "stop"; then
    stop_main
  elif test $input_action = "restart"; then
    restart_main
  elif test $input_action = "remove"; then
    remove_main
  else
    echo "pass"
  fi
}
# main



# https://github.com/PostgREST/postgrest


docker pull postgres:14.2
mkdir -p /opt/pg/data
docker run --name postgres14 \
  --restart=always \
  -e POSTGRES_PASSWORD=qiuwen123456 \
  -p 5433:5432 \
  -v /opt/pg/data:/var/lib/postgresql/data \
  -d postgres:14.2
docker stop postgres14 && docker rm postgres14




# (pytest) fhj@vb1:/opt$ lsb_release  -a
# No LSB modules are available.
# Distributor ID:	Ubuntu
# Description:	Ubuntu 22.04.4 LTS
# Release:	22.04
# Codename:	jammy



# https://blog.csdn.net/inthat/article/details/112168137
# apt-get install postgresql-client

#  apt show postgresql
#  apt install postgresql

# service postgresql status
# service postgresql stop


# ALTER USER postgres WITH PASSWORD 'qw123666';
# CREATE DATABASE data OWNER postgres;

# pg配置文件位置
# /etc/postgresql/14/main

# postgresql.conf修改


# pg_hba.conf 修改